package at.jku.pervasive.gui.model;

import java.util.List;

import javax.swing.DefaultComboBoxModel;

import at.jku.pervasive.Application;
import at.jku.pervasive.ApplicationListener;
import at.jku.pervasive.TagAssignment;

public class TagAssignmentModel extends DefaultComboBoxModel implements ApplicationListener
{

	private Application instance;
	private final TagAssignment tagPosition;

	public TagAssignmentModel(TagAssignment tagPosition)
	{
		super();

		this.tagPosition = tagPosition;

		instance = Application.getInstance();
		instance.addApplicationListener(this);
	}

	@Override
	public void setSelectedItem(Object anObject)
	{
		super.setSelectedItem(anObject);

		String tagId = (String) anObject;
		instance.tagAssignmentChanged(tagPosition, tagId);
	}

	@Override
	public int getSize()
	{
		return instance.getNumberOfTracingTagIds();
	}

	@Override
	public Object getElementAt(int index)
	{
		List<String> list = instance.getTracedTagIds();
		return list.get(index);
	}

	@Override
	public void startedListening(String host, int port)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void startedTracingTag(String tagId)
	{
		fireContentsChanged(this, 0, 0);
	}

	@Override
	public void stoppedListening(String host, int port)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void stoppedTracingTag(String tagId)
	{
		fireContentsChanged(this, 0, 0);
	}

	@Override
	public void tagAssignmentChanged(TagAssignment tagPosition, String tagId)
	{
		// TODO Auto-generated method stub

	}

}
